package com.eboss2.sbs.activity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.eboss2.sbs.R;
import com.eboss2.sbs.activity.base.BaseActivity;
import com.eboss2.sbs.config.Config;
import com.eboss2.sbs.http.HttpUtil;
import com.eboss2.sbs.model.PointBalanceInfo;
import com.eboss2.sbs.model.ProfitInfoManager;
import com.eboss2.sbs.myapplication.MyApplication;
import com.eboss2.sbs.weight.DialogUtils;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.loopj.android.http.RequestParams;
import com.mytools.tool.activityManager.MyActivityManager;
import com.tool.utils.utils.StringUtils;
import com.tool.utils.utils.ToastUtils;

import org.json.JSONObject;

public class MyProfitActivity extends BaseActivity implements View.OnClickListener{

	private static final String TAG = "MyProfitActivity";

	private TextView tv_amt;
	private TextView tv_pre_month;
	private TextView tv_pre_amt;
	private TextView tv_pre_person_num;
	private TextView tv_pre_member_amt;
	private TextView tv_total_amt;
	private TextView tv_get_person_num;
//	private TextView id_comfirm;


	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		mContext = this;
		setContentView(R.layout.activity_my_profit);
		MyActivityManager.getInstance().addActivity(this);
		initView();
		getdata();
	}
	
	private void initView(){
		RelativeLayout relativeLayout = relativeLayout(R.id.lv_heard);
		relativeLayout.setBackgroundColor(getResources().getColor(R.color.statusBar));
		showView(R.id.titleback_btn_back, true);
		setTvText(R.id.tv_title, "分润管理");
		showView(R.id.next_sure, true);
		setTvText(R.id.next_sure, "分润明细");
		findViewById(R.id.titleback_btn_back).setOnClickListener(this);
		findViewById(R.id.next_sure).setOnClickListener(this);

		tv_amt = textView(R.id.tv_amt);

		tv_pre_month = textView(R.id.tv_pre_month);
		tv_pre_amt = textView(R.id.tv_pre_amt);
		tv_pre_person_num = textView(R.id.tv_pre_person_num);
		tv_pre_member_amt = textView(R.id.tv_pre_member_amt);
		tv_total_amt = textView(R.id.tv_total_amt);
		tv_get_person_num = textView(R.id.tv_get_person_num);



//		relativeLayout(R.id.rl_hx).setOnClickListener(this);
//		textView(R.id.id_comfirm).setOnClickListener(this);
	}
	


	
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
			case R.id.titleback_btn_back:
				finish();
				break;
			case R.id.next_sure:
				startActivity(new Intent(mContext, MyProfitDetailActivity.class));
				break;
//			case R.id.id_comfirm:
//				String str = "2017年11月1日 00:00:00 -- 2017年11月30日 23:59:59\n" +
//						"共收益983.00元,确认后,金额将不可变化,账户余额将入账983.00元，请确认。";
//				DialogUtils.showComfirmProfitDialog(mContext, str, null);
//				break;
			default:break;
		}
	}



	private void getdata() {

		showProgress("加载中...");
		RequestParams params = new RequestParams();

		params.put("shopId", MyApplication.getmInstance().getLoginMEntity().getShopid() + "");
		HttpUtil.get(Config.SBS_PROFIT_MANAGER, params, new HttpUtil.RequestListener() {
			@Override
			public void success(String response) {
				disShowProgress();
				try {
					JSONObject result = new JSONObject(response);

					if (!result.optBoolean("status")) {
						ToastUtils.CustomShow(mContext, result.optString("message"));
					} else {
						ProfitInfoManager profitInfoManager = new Gson().fromJson(result.optString("data"), new TypeToken<ProfitInfoManager>() {
						}.getType());
						if (profitInfoManager != null) {
							tv_pre_month.setText("上月收益("+profitInfoManager.getLastTime()+"): ");
							tv_amt.setText(StringUtils.formatIntMoney(profitInfoManager.getThisMonthProfit()));
							tv_pre_amt.setText("￥"+StringUtils.formatIntMoney(profitInfoManager.getLastMonthProfit()));
							tv_pre_person_num.setText(profitInfoManager.getLastCustomerCount()+"");
							tv_pre_member_amt.setText(StringUtils.formatIntMoney(profitInfoManager.getLastCustomerAmount()));
							tv_total_amt.setText(StringUtils.formatIntMoney(profitInfoManager.getAllGetAmount()));
							tv_get_person_num.setText(profitInfoManager.getDevMemberCount()+"");
						}
					}
				} catch (Exception e) {
					Log.e(TAG, "doLogin() Exception: " + e.getMessage());
				}


			}

			@Override
			public void failed(Throwable error) {
				disShowProgress();
				showE404();
			}
		});
	}

	
}
